﻿namespace Nomo.UnityCoreModule
{
    /// <summary>
    /// 表示 4 个单精度浮点值的组合。
    /// </summary>
    [System.Serializable]
    public struct Float4
    {
        /// <summary>
        /// x 分量。
        /// </summary>
        public float x;

        /// <summary>
        /// y 分量。
        /// </summary>
        public float y;

        /// <summary>
        /// z 分量。
        /// </summary>
        public float z;

        /// <summary>
        /// w 分量。
        /// </summary>
        public float w;

        /// <summary>
        /// 使用 4 个分量初始化 <see cref="Float4"/> 结构的新值。
        /// </summary>
        /// <param name="x">x 分量。</param>
        /// <param name="y">y 分量。</param>
        /// <param name="z">z 分量。</param>
        /// <param name="w">w 分量。</param>
        public Float4(float x, float y, float z, float w)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            this.w = w;
        }

        /// <summary>
        /// 将 <see cref="Float4"/> 结构的值转换为 <see cref="UnityEngine.Vector4"/> 结构的值。
        /// </summary>
        /// <param name="float4"><see cref="Float4"/> 结构的值。</param>
        /// <returns><see cref="UnityEngine.Vector4"/> 结构的值。</returns>
        public static explicit operator UnityEngine.Vector4(Float4 float4)
        {
            return new UnityEngine.Vector4(float4.x, float4.y, float4.z, float4.w);
        }

        /// <summary>
        /// 将 <see cref="UnityEngine.Vector4"/> 结构的值转换为 <see cref="Float4"/> 结构的值。
        /// </summary>
        /// <param name="vector"><see cref="UnityEngine.Vector4"/> 结构的值。</param>
        /// <returns><see cref="Float4"/> 结构的值。</returns>
        public static explicit operator Float4(UnityEngine.Vector4 vector)
        {
            return new Float4(vector.x, vector.y, vector.z, vector.w);
        }

        /// <summary>
        /// 将 <see cref="Float4"/> 结构的值转换为 <see cref="UnityEngine.Quaternion"/> 结构的值。
        /// </summary>
        /// <param name="float4"><see cref="Float4"/> 结构的值。</param>
        /// <returns><see cref="UnityEngine.Quaternion"/> 结构的值。</returns>
        public static explicit operator UnityEngine.Quaternion(Float4 float4)
        {
            return new UnityEngine.Quaternion(float4.x, float4.y, float4.z, float4.w);
        }

        /// <summary>
        /// 将 <see cref="UnityEngine.Quaternion"/> 结构的值转换为 <see cref="Float4"/> 结构的值。
        /// </summary>
        /// <param name="quaternion"><see cref="UnityEngine.Quaternion"/> 结构的值。</param>
        /// <returns><see cref="Float4"/> 结构的值。</returns>
        public static explicit operator Float4(UnityEngine.Quaternion quaternion)
        {
            return new Float4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
        }
    }
}
